package com.gxa.meiye.admin.platform.controller;

import com.gxa.meiye.admin.platform.pojo.vo.AddCouponVo;
import com.gxa.meiye.admin.platform.pojo.vo.CouponManageVo;
import com.gxa.meiye.admin.platform.pojo.vo.DetailsCouponVo;
import com.gxa.meiye.admin.platform.pojo.vo.DetailsUserCouVo;
import com.gxa.meiye.admin.platform.service.CouponManageServcie;
import com.gxa.meiye.core.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api
@RestController
@RequestMapping("/platform/couponmanage")
public class CouponmanageController {

    @Resource
    private CouponManageServcie couponManageServcie;
    @ApiOperation("优惠券管理（点击优惠券管理渲染）")
    @GetMapping("/couponmanage/queryAll")
    public Map queryAll(){
        List<CouponManageVo> couponManageVos = this.couponManageServcie.queryAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(couponManageVos);
        jsonResult.setMsg("查询成功");
        return jsonResult.getMap();
    }

    @ApiOperation("搜索优惠券")
    @PostMapping("/couponmanage/selectAll")
    public Map selectAll(String name_id){
        List<CouponManageVo> couponManageVos = this.couponManageServcie.selectAll(name_id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(couponManageVos);
        jsonResult.setMsg("查询成功");
        return jsonResult.getMap();
    }
    @ApiOperation("新增")
    @PostMapping("/couponmanage/addCoupon")
    public Map addCoupon(@RequestBody AddCouponVo addCouponVo) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new Date());
        int status = 1;
        this.couponManageServcie.addCoupon(addCouponVo.getCoupon_id(),addCouponVo.getTitle(),addCouponVo.getType(),addCouponVo.getMoney(),addCouponVo.getDatatime(),addCouponVo.getTotal(),status,addCouponVo.getUser_max(),addCouponVo.getIssuing_conditions(),addCouponVo.getTotal(),format);
        List<CouponManageVo> couponManageVos = this.couponManageServcie.queryAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(couponManageVos);
        jsonResult.setMsg("新增成功");
        return jsonResult.getMap();
    }
    @ApiOperation("删除")
    @PostMapping("/couponmanage/deleteCoupon")
    public Map deleteCoupon(Integer id){
        this.couponManageServcie.deleteCoupon(id);
        System.out.println(id);
        List<CouponManageVo> couponManageVos = this.couponManageServcie.queryAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(couponManageVos);
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }
    @ApiOperation("详情")
    @PostMapping("/couponmanage/detailsCoupon")
    public Map detailsCoupon(Integer id){
        Map map = new HashMap();
        List<DetailsCouponVo> detailsCouponVos = this.couponManageServcie.queryCoupon(id);
        List<DetailsUserCouVo> detailsUserCouVos = this.couponManageServcie.queryCouponde(id);
        map.put("detailsCouponVos",detailsCouponVos);
        map.put("detailsUserCouVos",detailsUserCouVos);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        jsonResult.setMsg("查询成功");
        return jsonResult.getMap();
    }
    @ApiOperation("查询发放详情")
    @PostMapping("/couponmanage/selectsendCoupon")
    public Map senddetailsCoupon(String tempall){
        List<DetailsUserCouVo> detailsUserCouVos = this.couponManageServcie.selectCouponde(tempall);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(detailsUserCouVos);
        jsonResult.setMsg("查询成功");
        return jsonResult.getMap();
    }
}
